<template>
	<view style="padding: 30rpx;">
		<view class="coupon-view mb-3" v-for="(item,index) in list" :key="index">
			<view class="coupon-view-left">
			   <text style="font-size: 30px;color: #F26D72;margin-right: 10rpx;">{{item.money}}</text>
			   <text style="font-size: 13px;color: #333333;">元</text>
			</view>
			<view class="">
				<view style="font-size: 15px;margin-bottom: 10rpx;">{{item.title}}</view>
				<view style="font-size: 13px;color: #999999;margin-bottom: 10rpx;">
				   满{{item.max_money}}元减{{item.money}}元
				</view>
				<view style="font-size: 13px;color: #999999;margin-bottom: 10rpx;">有效期{{item.valid}}天</view>
				<!-- <view style="font-size: 13px;color: #999999;">全平台可用</view> -->
			</view>
			<view class="coupon-view-btn" @click="getCoupop(item.id)">点击领取</view>
		</view>
		<u-empty v-if="list.length == 0"
		        mode="list"
		        icon="http://cdn.uviewui.com/uview/empty/list.png"
				width="150px"
				height="150px"
				text="列表为空"
				textSize="18"
		>
		</u-empty>
		<view style="padding-bottom: 100rpx;">
			<u-loadmore v-if="loading" status="loading" />
			<u-loadmore v-if="isLastPage" status="nomore" />
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				page:1,
				limit:10,
				list:[],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.CouponList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.CouponList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.CouponList();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			CouponList() {
				let parmar = {
					page: this.page,
					limit: this.limit,
				}
				this.$api.getCouponList(parmar).then(res => {
					if (res.code === 1) {
						 this.list = [...this.list, ...res.data.data]
					}
				})
			},
			getCoupop(id){
				this.$api.couponReceive({coupon_id:id}).then(res=>{
					if(res.code ==1){
						uni.showToast({
							title:'领取成功',
							icon:'none'
						})
						this.page = 1
						this.limit = 10
						this.list = []
						this.CouponList()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.coupon-view{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
	}
	.coupon-view-btn{
		width: 128rpx;
		height: 50rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #008F3D;
		text-align: center;
		line-height: 50rpx;
		border-radius: 25rpx;
		border: 1rpx solid #008F3D;
	}
</style>